<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<s:hidden value="%{user.userId}" id="userId"></s:hidden>
<s:hidden value="%{province}" id="pro"></s:hidden>
<s:hidden value="%{citys}" id="city" ></s:hidden>
<s:hidden value="%{countys}" id="county" ></s:hidden>
<s:hidden value="%{streets}" id="street" ></s:hidden>
<div>
<select name="province" id="province" onchange="getCitys()" style="width:92px">
<option value="" id="">省份</option>
</select>
<select name="citys" id="citys" onchange="getCountys()" style="width:91px">
<option value="">城市</option>
</select>
<select name="countys" id="countys" onchange="getStreets()" style="width:91px">
<option value="">县/区</option>
</select>
<select name="streets" id="streets" style="width:92px">
<option value="">街道</option>
</select>
</div>
<script type="text/javascript">
var pro=$("#pro").val();
var city=$("#city").val();
var county=$("#county").val();
var street=$("#street").val();
	$.ajax({
        type:"post",
        url:"<%=basePath%>adr/adr_getProvinces",
        dataType:"json",
        success:function(data){
           // alert(data.length);
            var province=$("#province");
            var option="";
            for(var i=0;i<data.length;i++){
                if(data[i].proName==pro){
                	option +="<option id='"+data[i].proId+"' value='"+data[i].proName+"' selected=true>"+data[i].proName+"</option>";
                    }else{
                  option +="<option id='"+data[i].proId+"' value='"+data[i].proName+"'>"+data[i].proName+"</option>";
                    }
                }
            province.append(option);
            }
		});

function getCitys(){
	var city=$("#province option:selected").attr("id");
	$.ajax({
        type:"post",
        url:"<%=basePath%>adr/adr_getCitys",
        data:{proId:city},
        dataType:"json",
        success:function(data){
           // alert(data.length);
            var citys=$("#citys");
            var option="";
            citys.find("option").remove();
            citys.append("<option value=\"\">城市</option>");
            for(var i=0;i<data.length;i++){
                if(data[i].cityName==city){
                	 option +="<option id='"+data[i].cityId+"' value='"+data[i].cityName+"' selected=true>"+data[i].cityName+"</option>";
                    }else{
                  option +="<option id='"+data[i].cityId+"' value='"+data[i].cityName+"'>"+data[i].cityName+"</option>";
                }
            }
            citys.append(option);
            }
		});
}
function getCountys(){
	var county=$("#citys option:selected").attr("id");
	$.ajax({
        type:"post",
        url:"<%=basePath%>adr/adr_getCountys",
        data:{cityId:county},
        dataType:"json",
        success:function(data){
           // alert(data.length);
            var countys=$("#countys");
            var option="";
            countys.find("option").remove();
            countys.append("<option value=\"\">县/区</option>");
            for(var i=0;i<data.length;i++){
                if(data[i].countyName==county){
                	option +="<option id='"+data[i].countyId+"' value='"+data[i].countyName+"' selected=true>"+data[i].countyName+"</option>";
                    }else{
                    	option +="<option id='"+data[i].countyId+"' value='"+data[i].countyName+"'>"+data[i].countyName+"</option>";
                        }
                  
                }
            countys.append(option);
            }
		});
}
function getStreets(){
	var streets=$("#countys option:selected").attr("id");
	$.ajax({
        type:"post",
        url:"<%=basePath%>adr/adr_getStreets",
        data:{countyId:streets},
        dataType:"json",
        success:function(data){
           // alert(data.length);
            var streets=$("#streets");
            var option="";
            streets.find("option").remove();
            streets.append("<option value=\"\">街道</option>");
            for(var i=0;i<data.length;i++){
                if(data[i].streetName==street){
                	 option +="<option id='"+data[i].streetId+"' value='"+data[i].streetName+"' selected=true>"+data[i].streetName+"</option>";
                    }else{
                    	 option +="<option id='"+data[i].streetId+"' value='"+data[i].streetName+"'>"+data[i].streetName+"</option>";
                        }
                 
                }
            streets.append(option);
            }
		});
}
if($("#userId").val()!=null){
	getCitys();
	getCountys();
	getStreets();
	
}
</script>
</body>
</html>